package Demo3;

/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.05.00
 *Time:00:00
 */

import java.util.Objects;

class Money implements Cloneable{

    public double money = 99.99;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
public class Person implements Cloneable{

    //成员属性
    public String name;
    int age;

    public Money m = new Money();

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

//    @Override
//    protected Object clone() throws CloneNotSupportedException{
//        return super.clone();
//    }

    @Override
    protected Object clone()  throws CloneNotSupportedException{

       Person tem = (Person)super.clone();//创建一个临时引用
       tem.m = (Money) this.m.clone();
       return tem;
    }

}
